import { Form, Input, Button, message } from 'antd';
import login from '../../api/auth';
// import { useNavigate } from 'react-router-dom';

const Index = () => {

    // const navigate = useNavigate();
    const onFinish = async (values) => {
        try {
            await login(values);
            window.location.replace('/');
        } catch (error) {
            message.error(error.message || '登录失败');
        }
    };


    return (
        <div style={{ width: 300, margin: '100px auto' }}>
            <Form onFinish={onFinish}>
                <Form.Item
                    name="account"
                    rules={[{ required: true, message: '请输入用户名' }]}
                >
                    <Input placeholder="用户名" />
                </Form.Item>
                <Form.Item
                    name="password"
                    rules={[{ required: true, message: '请输入密码' }]}
                >
                    <Input.Password placeholder="密码" />
                </Form.Item>
                <Button type="primary" htmlType="submit" block>
                    登录
                </Button>
            </Form>
        </div>
    )
}

export default Index;